import redis
from sshtunnel import SSHTunnelForwarder
def main():
    server = SSHTunnelForwarder(
        ssh_address_or_host=('101.132.42.244', 22),
        ssh_username='root',  # 云服务器登录账号admin
        ssh_password='Cws961112',  # 云服务器登录密码password
        remote_bind_address=('localhost', 6379)  # 数据库服务地址ip,一般为localhost和端口port，一般为3306
    )

    # 云服务器开启
    server.start()
    client=redis.Redis(host='127.0.0.1',port=server.local_bind_port)
    client.set('username','hellokitty',ex=300)
    client.set('math score',88)
    client.incr('math score')
    print(client.get('math score').decode())
    client.incrby('math score',10)
    print(client.get('math score').decode())
    print(client.ttl('username'))
    print(client.get('username').decode())
    server.close()
if __name__ == '__main__':
    main()